package com.gem.demo.controller;

import com.gem.demo.entity.Product;
import com.gem.demo.service.ProductService;
import com.gem.demo.util.PageUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/*
* service:查询某页
* mapper:查询所有
*
* */
@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
       private ProductService productService;
    @RequestMapping("/index")
    public  String index(@RequestParam(defaultValue = "1",required = false)int pageNum, Model model){
        PageInfo<Product>pageInfo= productService.listPage(pageNum, PageUtil.pageSize);
        //pageInfo中包含了  查询数据  分页  页码  总页码 所有页码数
       model.addAttribute("productPage",pageInfo);
       model.addAttribute("currPageNum",pageNum);
        return "admin/show";
    }
}
